﻿SET QUOTED_IDENTIFIER ON
GO
SET ARITHABORT ON
GO
SET NUMERIC_ROUNDABORT OFF
GO
SET CONCAT_NULL_YIELDS_NULL ON
GO
SET ANSI_NULLS ON
GO
SET ANSI_PADDING ON
GO
SET ANSI_WARNINGS ON
GO

CREATE PROCEDURE bhp_temp_Extend
AS
BEGIN
	CREATE TABLE dbo.bht_PagesFunctionality
		(
		PageID int NOT NULL,
		Functionality nvarchar(50) NOT NULL
		)  ON [PRIMARY]
	
	ALTER TABLE dbo.bht_PagesFunctionality ADD CONSTRAINT
		PK_bht_PagesFunctionality PRIMARY KEY CLUSTERED 
		(
		PageID
		) ON [PRIMARY]

	
	ALTER TABLE dbo.bht_PagesFunctionality ADD CONSTRAINT
		FK_bht_PagesFunctionality_mp_Pages FOREIGN KEY
		(
		PageID
		) REFERENCES dbo.mp_Pages
		(
		PageID
		) ON UPDATE  NO ACTION 
		 ON DELETE  NO ACTION 
	
	
END
GO
EXEC bhp_temp_Extend
GO
DROP PROCEDURE bhp_temp_Extend
GO
CREATE PROCEDURE [dbo].[bhp_FindPageByFunctionality]
(
	@Function	NVARCHAR(400),
	@SiteId		INT = 1
)
AS
BEGIN

	SELECT
		PageGuid
	FROM
		mp_Pages p
		INNER JOIN bht_PagesFunctionality f ON p.PageID = f.PageID
	WHERE
		f.Functionality = @Function
		AND p.SiteId = @SiteId

END